package com.juzi.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class Dom4jDemo {
    @Test
    public void parseXMLData() throws Exception {
        SAXReader saxReader = new SAXReader();

//        Document document = saxReader.read(new File("src\\Contacts.xml"));
//        Document document = saxReader.read(new FileInputStream("src\\Contacts.xml"));

        //注意：“/”是直接找src下的文件，不会因为工程改名而出问题
        InputStream is = Dom4jDemo.class.getResourceAsStream("/Contacts.xml");
        Document document = saxReader.read(is);

        Element root = document.getRootElement();
        System.out.println(root.getName());
    }
}
